<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>


    // async await 是Promise的语法糖
    // Promise.all
    // 作用： 同时发送多个请求，而且不阻塞，并且同时成功
    // 语法： Promise.all([p1, p2, p3]).then(( [res1, res2, res3]) => {

    // })
    function fn1(params) {
      return new Promise((resolve) => {
        setTimeout(() => {
          resolve('1')
        }, 1000)
      })
    }

    function fn2(params) {
      return new Promise((resolve) => {
        setTimeout(() => {
          resolve('2')
        }, 2000)
      })
    }

    function fn3(params) {
      return new Promise((resolve) => {
        setTimeout(() => {
          resolve('3')
        }, 3000)
      })
    }


    console.time() // 开启即时
    Promise.all([fn1(), fn2(), fn3()]).then((res) => {
      console.log('res  ----->  ', res);
      console.log('三个Promise同时结束, 耗时  ----->  ', console.timeEnd());
      // 停止计时， 计算耗时
    })

  </script>
</body>

</html>